

/**
 * Add a note
 * @return
 */
function add(){
	var url = "ajaxaddnote.action";
	var select = document.getElementById("select_note_category_add");
	var remark = document.getElementById("select_note_remark_add").value;
	var claimId = document.getElementById("claim_id").value;
	if(checkRemark(remark)){
		var params = {"note.noteCategory":select.options[select.selectedIndex].text,
						"note.remark":remark,
						"note.claimId":claimId}; 
		$.ajax({
	        type:"POST",
	        async:false,
	        url:url,
	        data:params,
	        success:function(data) {
		
				document.getElementById("select_note_remark_add").value = '';
				alert("备注添加成功！");
				if(document.getElementById("note_list_flag").value == 'noteListFlag'){
					document.getElementById("noteForm").submit();
			}
	          }
	    });
		showComment();
	}else{
		resetButton();
	}
}

function disableMe(button){
	button.disabled = "true";
}

function resetButton(){
	$("#ok_button").attr("disabled",false);
}
/**
 * check remark
 * @param remark
 * @return
 */
function checkRemark(remark){
	if(remark == ''){
		alert("备注不能为空！");
		return false;
	}
	if(remark.length > 255){
		alert("备注信息不能超过255个字符！");
		return false;
	}
	return specialChar(remark);
}

function specialChar(str){
	var patrn=/[\$%\^&*()]/; 
	if(patrn.exec(str)){
		alert("存在非法字符");
		return false;
	}
	return true;
}

function showTopComment(){
	var dialog = $('#topComment');
	if(dialog.dialog( 'isOpen' )){	
		dialog.dialog( 'close' );
	}else{
		dialog.dialog( 'open' );
		$("#topNoteComment").focus();
	}	
}

function addTopComment(){
	var remark = $("#topNoteComment").val();
	if(!checkRemark(remark)){
		return false;
	}
	showTopComment();
	var url = "ajaxaddnote.action";
	var category = $("#top_select_note_category").val();
	var claimId = $("#claim_id").val();
	var params = {"note.noteCategory":category,	"note.remark":remark, "note.claimId":claimId };
	$.post(url, params, function(){
			alert("备注添加成功！");
			if(typeof(needRefresh)!="undefined"){
				var currentVersionId = $("#currentVersionId").val();
				var claimId = $("#claim_id").val();
				var result = $("#result").val();
				window.location.href = "notelist.action?currentVersionId="+currentVersionId+"&claimId="+claimId+"&result="+result;
			}
		}
	);	
	return true;
}

function findTopNoteCategoryList(){
	var url = "ajaxfindnotecategorylist.action";
	$.post(url, function(data){
		    var category = $('#top_select_note_category');
		    category.html(data);
			}
	);	
}

function toTopComment(){
	findTopNoteCategoryList();
	$("#topNoteComment").val("");
	showTopComment();
}
